package views;

import entity.Goods;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Login {
    UserView userView=new UserView();
    GoodsView goodsView=new GoodsView();
    BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
    int tool=0;
    boolean judgement=false;
    String a=null;
    public void login(){
        try {
            System.out.println("————————是否进入二手交易系统？——————————");
            System.out.println("——————————如果进入系统请输入是，如果要不进入系统输入其他即可————————");
            a=bufferedReader.readLine();
            while (a.equals("是")){
                System.out.println("欢迎来到二手交易系统！！！");
                System.out.println("——————————请输入你要进入的界面——————————");
                System.out.println("1.用户登录，2.商户登录，3.管理员登录，4.用户注册，5，商户注册");
                try {
                    switch (Integer.parseInt(bufferedReader.readLine())){
                        case 1:
                            judgement=userView.customerLoginView();
                            tool=1;
                            break;
                        case 2:
                            judgement=userView.sellerLoginView();
                            tool=2;
                            break;
                        case 3:
                            judgement=userView.administratorLoginView();
                            tool=3;
                            break;
                        case 4:
                            userView.registerCustomerView();
                            judgement=userView.customerLoginView();
                            tool=1;
                            break;
                        case 5:
                            userView.registerSellerView();
                            judgement=userView.sellerLoginView();
                            tool=2;
                            break;
                        default:
                            System.out.println("输入指令异常！");
                            break;
                    }
                    if (judgement&&tool==3){
                        System.out.println("-------请输入你要进入的界面----------");
                        System.out.println("1.增加用户 2.删除用户 3.更改用户 4.查询用户 5.添加商品 6.删除商品 7.更改商品 8.查询商品");
                        switch (Integer.parseInt(bufferedReader.readLine())){
                            case 1:
                                userView.insertUserView();
                                break;
                            case 2:
                                userView.deleteUserView();
                                break;
                            case 3:
                                userView.updateUserView();
                                break;
                            case 4:
                                userView.selectUserViewO();
                                break;
                            case 5:
                                goodsView.insertGoodsView();
                                break;
                            case 6:
                                goodsView.deleteGoodsView();
                                break;
                            case 7:
                                goodsView.updateGoodsView();
                                break;
                            case 8:
                                goodsView.selectGoodsView();
                                break;
                            default:
                                System.out.println("输入指令错误！");
                                break;
                        }
                    }else if (judgement&&tool==2){
                        System.out.println("-------请输入你要进入的界面----------");
                        System.out.println("1.更改个人信息 2.查询商品 3.上架商品 4.下架商品 5.更换商品 ");
                        switch (Integer.parseInt(bufferedReader.readLine())){
                            case 1:
                                userView.updateUserView();
                                break;
                            case 2:
                                goodsView.selectGoodsView();
                                break;
                            case 3:
                                goodsView.insertGoodsView();
                                break;
                            case 4:
                                goodsView.deleteGoodsView();
                                break;
                            case 5:
                                goodsView.updateGoodsView();
                                break;
                            default:
                                System.out.println("输入指令错误！");
                                break;
                        }
                    }else if (judgement&&tool==1){
                        System.out.println("-------请输入你要进入的界面----------");
                        System.out.println(" 1.更改个人信息 2.选货 3.退货 4.换货 5.搜索商品");
                        switch (Integer.parseInt(bufferedReader.readLine())){
                            case 1:
                                userView.updateUserView();
                                break;
                            case 2:
                                goodsView.buyGoodsView();
                                break;
                            case 3:
                                goodsView.returnGoodsView();
                                break;
                            case 4:
                                goodsView.changeGoodsView();
                                break;
                            case 5:
                                goodsView.selectGoodsView();
                                break;
                            default:
                                System.out.println("输入指令错误！");
                                break;
                        }
                    }
                }catch (IOException e){
                    System.out.println("io异常，进入失败！");
                }
                System.out.println("是否重新进入系统？");
                System.out.println("如果重新进入请输入是，如果要退出系统输入其他即可");
                a=bufferedReader.readLine();
            }
            System.out.println("欢迎下次进入！");
        }catch (IOException e){
            System.out.println("io异常，进入失败！");
        }
    }
}


